#include "idcardwgt.h"

IDCardWgt::IDCardWgt(QWidget *parent) : QWidget(parent)
{
    m_pLabTitle = new QLabel(tr("Info"),this);
    m_pLabName = new QLabel(tr("Name:"),this);
    m_pLabNameTxt = new QLabel(this);

    m_pLabGender = new QLabel(tr("Gender:"),this);
    m_pLabGenderTxt = new QLabel(this);

    m_pLabEthnicity = new QLabel(tr("Ethnicity:"),this);
    m_pLabEthnicityTxt = new QLabel(this);

    m_pLabBirth = new QLabel(tr("Date of Birth:"),this);
    m_pLabBirthTxt = new QLabel(this);

    m_pLabAddr = new QLabel(tr("Residential Address:"),this);
    m_pLabAddrTxt = new QLabel(this);
    m_pLabAddrTxt->setWordWrap(true);
    m_pLabAddrTxt->setAlignment(Qt::AlignTop);

    m_pLabID = new QLabel(tr("Citizen ID number:"),this);
    m_pLabIDTxt = new QLabel(this);
    m_pLabAuthority = new QLabel(tr("Authority:"), this);
    m_pLabAuthorityTxt = new QLabel(this);

    m_pLabValidity = new QLabel(tr("Validity:"),this);
    m_pLabValidityTxt = new QLabel(this);

    m_pLabPhoto = new QLabel(this);
    m_pLabPhoto->setStyleSheet("background-color: rgb(219,219,219)");
    m_pLabPhoto->setScaledContents(true);

    m_pIDCardReadDatang = new IDCardReadDatang(this);

    qRegisterMetaType<ST_ID_INFO>("ST_ID_INFO&");
    connect(m_pIDCardReadDatang, SIGNAL(sigIdcardInfo(ST_ID_INFO&, QPixmap)),
            this, SLOT(slotIdCardInfo(ST_ID_INFO&, QPixmap)));

    m_pIDCardReadDatang->start();

    m_pIdCardOcr = new IdCardOcr(this);
    m_pIdCardOcr->start();
    connect(m_pIdCardOcr, SIGNAL(sigIdcardInfo(ST_ID_INFO&, QPixmap)),
            this, SLOT(slotIdCardInfo(ST_ID_INFO&, QPixmap)));

}

IDCardWgt::~IDCardWgt()
{

}

void IDCardWgt::resizeEvent(QResizeEvent *event)
{
    QSize size = event->size();
    int nW = size.width();
    int nL1 = 10;
    int nW1 = 120;
    int nH1 = 15;
    int nTop = 30;
    int nGapLab = 30;
    m_pLabTitle->setGeometry(nL1, nTop, nW1, nH1);
    m_pLabPhoto->setGeometry(nW/2-51, nTop+30, 102, 126);
    m_pLabName->setGeometry(nL1, nTop+170, nW1, nH1);
    m_pLabNameTxt->setGeometry(nL1+nW1, nTop+170, nW1, nH1);
    m_pLabGender->setGeometry(nL1, nTop+nH1+nGapLab+170, nW1, nH1);
    m_pLabGenderTxt->setGeometry(nL1+nW1, nTop+nH1+nGapLab+170, nW1, nH1);
    m_pLabBirth->setGeometry(nL1, nTop+2*nH1+2*nGapLab+170, nW1, nH1);
    m_pLabBirthTxt->setGeometry(nL1+nW1, nTop+2*nH1+2*nGapLab+170, nW1, nH1);
    m_pLabEthnicity->setGeometry(nL1, nTop+3*nH1+3*nGapLab+170, nW1, nH1);
    m_pLabEthnicityTxt->setGeometry(nL1+nW1, nTop+3*nH1+3*nGapLab+170, nW1, nH1);
    m_pLabAddr->setGeometry(nL1, nTop+4*nH1+4*nGapLab+170, nW1, nH1);
    m_pLabAddrTxt->setGeometry(nL1+nW1, nTop+4*nH1+4*nGapLab+170, nW1, 5*nH1);
    m_pLabID->setGeometry(nL1, nTop+6*nH1+6*nGapLab+170, nW1, 20);
    m_pLabIDTxt->setGeometry(nL1+nW1, nTop+6*nH1+6*nGapLab+170, 180, 20);
    m_pLabAuthority->setGeometry(nL1, nTop+7*nH1+7*nGapLab+170, nW1, 20);
    m_pLabAuthorityTxt->setGeometry(nL1+nW1, nTop+7*nH1+7*nGapLab+170, nW1, 20);
    m_pLabValidity->setGeometry(nL1, nTop+8*nH1+8*nGapLab+170, nW1, 20);
    m_pLabValidityTxt->setGeometry(nL1+nW1, nTop+8*nH1+8*nGapLab+170, 160, 20);
}

void IDCardWgt::slotIdCardInfo(ST_ID_INFO &stIdInfo, QPixmap pixMap)
{
    m_pLabNameTxt->setText(stIdInfo.strName);
    m_pLabGenderTxt->setText(stIdInfo.strSex);
    m_pLabBirthTxt->setText(stIdInfo.strBirthday);
    m_pLabEthnicityTxt->setText(stIdInfo.strNation);
    m_pLabAddrTxt->setText(stIdInfo.strAddress);
    m_pLabIDTxt->setText(stIdInfo.strIDCode);
    m_pLabValidityTxt->setText(stIdInfo.strValideDate);
    m_pLabAuthorityTxt->setText(stIdInfo.strDepartment);    
    m_pLabPhoto->setPixmap(pixMap);
}
